package butines.game.steering.behavior;

import java.util.Collection;

import butines.core.math2d.Vector2D;
import butines.game.steering.Vehicle;

public class ObstacleAvoidanceBehavior extends AbstractBehavior {
	
	private Vehicle owner;
	private Collection<? extends Vehicle> obstacles;
	private Vector2D steeringForce = new Vector2D();

	public ObstacleAvoidanceBehavior(Vehicle owner) {
		if (owner == null) {
			throw new IllegalArgumentException("Argument 'owner' is null");
		}
		this.owner = owner;
	}
	
	public Collection<? extends Vehicle> getObstacles() {
		return obstacles;
	}

	public void setObstacles(Collection<? extends Vehicle> obstacles) {
		this.obstacles = obstacles;
	}
	
	public Vector2D calculate() {
		if (obstacles == null) {
			return steeringForce.set(0, 0);
		}
		obstacleAvoidance(steeringForce, owner, obstacles);
		return steeringForce.mult(getWeight());
	}

	public Vehicle getOwner() {
		return owner;
	}

	public Vector2D getSteeringForce() {
		return steeringForce;
	}

}
